<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加员工</title>
    <link rel="stylesheet" href="/asset/layui/css/layui.css">
    <link rel="stylesheet" href="/asset/css/index.css">
    <link rel="Shortcut Icon" href="cachet.ico">
    <script type="text/javascript" src="/asset/js/jquery-3.3.1.min.js"></script>
	<script src="/asset/layui/layui.js"></script>
    <script src="/asset/js/common.js"></script>
</head>
<body>
<style type="text/css">
	.content{
		width: auto;
		display: block;
	}
	.content .left{
		float: left;
		width: 180px;
		margin: 0px 8px 0 0;
		border: 1px solid #f4f6f5;
		background: #fff;
		padding-left: 8px;
	}
	
   .content .right{
    		border: 1px solid #f4f6f5;
	    background: #fff;
	    position:relative; 
	    overflow:hidden;
    }
    .footer{
		
		text-align: center;
		margin-top: 10px;
		background-color: #E3E3E3;
	}
</style>

	
	<div class="content">
		<div class="left">
			<iframe name="left"  id="leftMain" src="/staff/selected/orgs.htm" id="center_frame" src="" frameborder="false" scrolling="auto" style="border: none; height: 478px;" width="100%" height="auto" allowtransparency="true"></iframe>
		</div>
		<div class="right">
			<#if type =='SELECT_INTERIM_PERSON'>
			<div>
                <div class="layui-inline">
                    <label class="layui-form-label">失效时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="expiredDate" name="expiredDate" value="" placeholder="">
                    </div>
                </div>
	        </div>
	        </#if>
			<iframe name="right" id="rightMain" src="/staff/selected/staffs.htm" frameborder="false" scrolling="auto" style="border: none;  height: 478px;" width="100%" height="auto" allowtransparency="true"></iframe>
		</div>
	</div>
	<div class="footer">
		<button  class="layui-btn layui-btn-danger" lay-filter="add" lay-submit="">选择</button>
		<button  class="layui-btn layui-btn-primary" lay-filter="cancel" lay-submit="">取消</button>
	</div>
	
	
	<script>
        layui.use(['form','layer','laydate'], function(){
            $ = layui.jquery;
          var form = layui.form
          var laydate = layui.laydate
          ,layer = layui.layer;
          
          laydate.render({
		    elem: '#expiredDate' //指定元素
		  });

          //监听提交
          form.on('submit(add)', function(data){
            var $custosInfo = parent.$("#custosInfo");
            
            var $selectedId =  $("#rightMain").contents().find("input[name='selectedId']:checked");
            var selectedId = $selectedId.val(), data = $selectedId.attr("lay-data");
            
            if(!selectedId){
            		layer.msg("请选择保管员");
            }else{
           		var obj =  eval('(' + data + ')');
           		
           		if(!obj.portrait){
           			obj.portrait='/asset/images/portrait.png';
           		}
           		//console.log(obj);
           		
			         
			    
			    var selectType = '${type}';
			    //特批审核选择人
			    if(selectType == 'SELECT_SPECIAL_PERON'){
			    	
			    	var custosInfo = $([' <div class="user"><input type="hidden" name="specialPartyId" value="'+selectedId+'">'
							          	,'<div class="avatar"><img src="'+obj.portrait+'"  /></div>'
							            ,'<div class="info"><div class="name">'+obj.name+'</div><div class="position">'+obj.position+'</div></div>'
							         ,'</div>'].join(''));
			    
			    	var $specialPeronInfo = parent.$("#specialPeronInfo");
			    	$specialPeronInfo.html(custosInfo);
			    //选择保管员
			    }else if(selectType =='SELECT_CUSTOS_PERSON'){
			    	var custosInfo = $([' <div class="user"><input type="hidden" name="partyId" value="'+selectedId+'">'
							          	,'<div class="avatar"><img src="'+obj.portrait+'"  /></div>'
							            ,'<div class="info"><div class="name">'+obj.name+'</div><div class="position">'+obj.position+'</div></div>'
							         ,'</div>'].join(''));
			    
			    	var $custosPersonInfo = parent.$("#custosPersonInfo");
			    	$custosPersonInfo.html(custosInfo);
			    //选择印章审核人员
			    }else if(selectType =='SELECT_APPLY_PERSON'){
			    
			    	var $applyPersonInfo = parent.$("#applyPersonInfo");
			    	$applyPersonInfo.html(custosInfo);
			    	
			    	obj.id = selectedId;
		    		var $applyPersonData = parent.$("#applyPersonData");
		    		var applyPersonData = $applyPersonData.val()
		   			if(applyPersonData){
		   				var array = eval('(' + applyPersonData + ')');
		   				
		   				var b = false;
		   				for(var i=0;i<array.length;i++){
		   					if(array[i].id==selectedId){
		   						b = true;
		   						layer.msg("此人员已添加");
		   						return false;
		   					}
		   				}
		   				if(b){
		   					alert("此人员已添加");
		   					return false;
		   				}
		   				
		   				
		   				array.push(obj)
		   				$applyPersonData.val(JSON.stringify(array));
		   			}else{
		   				var array = new Array();
		   				array.push(obj);
		   				$applyPersonData.val(JSON.stringify(array));
		   			}
		    		parent.info();
			    	
			    
			    //设置临时保管员
			    }else if(selectType =='SELECT_INTERIM_PERSON'){
			    	 var expiredDate = $("#expiredDate").val();
			    	 if(!expiredDate){
			    	 	layer.msg('请选择失效时间');
			    	 	return false;
			    	 }
			    
			    	 var field = new Object();
			    	 field.interimPartyId = selectedId;
			    	 field.sealId = '${id}';
			    	 field.interimExpiredDate =expiredDate;
			         $.ajax({
			      			type:"POST", 
			      			url:"/seal/setInterim.htm",
			      			data:field,
			      			success:function(result) {
					      
					      		if(result.code=='1'){
					      			layer.alert("操作成功", {icon: 6},function () {
						                // 获得frame索引
						                 window.parent.location.reload();
						                var index = parent.layer.getFrameIndex(window.name);
						                //关闭当前frame
						                parent.layer.close(index);
						            });
					      		}else{
					      		 	layer.msg(result.msg);
					      		}
					      
					    	 } 
					    }); 
			           
			           return false;
			             
			           //selectedId        
			    }
			    
			     var index = parent.layer.getFrameIndex(window.name);
           		 parent.layer.close(index);
            }
            
            return false;
          });
          
          form.on('submit(cancel)', function(data){
            
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            
            return false;
          });
          
        });
    </script>
	
	
	
	
	
</body>
</html>